package com.zcxx.cotton.sale;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.page.TableDataInfo;
import com.zcxx.cotton.sale.domain.SaleInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zcxx.cotton.sale.domain.BuySubsidyRecords;
import com.zcxx.cotton.sale.service.IBuySubsidyRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 交售信息Controller
 *
 * @author ruoyi
 * @date 2025-09-19
 */
@RestController
@RequestMapping("/BuySubsidyRecords/BuySubsidyRecords")
public class BuySubsidyRecordsController extends BaseController {
    @Autowired
    private IBuySubsidyRecordsService buySubsidyRecordsService;

    /**
     * 查询交售信息列表
     */
    @PreAuthorize("@ss.hasPermi('BuySubsidyRecords:BuySubsidyRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuySubsidyRecords buySubsidyRecords) {
        try {
            startPage();
            startOrderBy();
            List<BuySubsidyRecords> list = buySubsidyRecordsService.selectBuySubsidyRecordsList(buySubsidyRecords);
            return getDataTable(list);
        } catch (Exception e) {
            e.printStackTrace();
            List<BuySubsidyRecords> list = buySubsidyRecordsService.selectBuySubsidyRecordsList(buySubsidyRecords);
            return getDataTable(list);
        }

    }

    /**
     * 导出交售信息列表
     */
    @PreAuthorize("@ss.hasPermi('BuySubsidyRecords:BuySubsidyRecords:export')")
    @Log(title = "交售信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuySubsidyRecords buySubsidyRecords) {
        List<BuySubsidyRecords> list = buySubsidyRecordsService.selectBuySubsidyRecordsList(buySubsidyRecords);
        ExcelUtil<BuySubsidyRecords> util = new ExcelUtil<BuySubsidyRecords>(BuySubsidyRecords.class);
        util.exportExcel(response, list, "交售信息数据");
    }

    /**
     * 获取交售信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('BuySubsidyRecords:BuySubsidyRecords:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(buySubsidyRecordsService.selectBuySubsidyRecordsById(id));
    }

    /**
     * 新增交售信息
     */
    @PreAuthorize("@ss.hasPermi('BuySubsidyRecords:BuySubsidyRecords:add')")
    @Log(title = "交售信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuySubsidyRecords buySubsidyRecords) {
        return toAjax(buySubsidyRecordsService.insertBuySubsidyRecords(buySubsidyRecords));
    }

    /**
     * 修改交售信息
     */
    @PreAuthorize("@ss.hasPermi('BuySubsidyRecords:BuySubsidyRecords:edit')")
    @Log(title = "交售信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuySubsidyRecords buySubsidyRecords) {
        return toAjax(buySubsidyRecordsService.updateBuySubsidyRecords(buySubsidyRecords));
    }

    /**
     * 删除交售信息
     */
    @PreAuthorize("@ss.hasPermi('BuySubsidyRecords:BuySubsidyRecords:remove')")
    @Log(title = "交售信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(buySubsidyRecordsService.deleteBuySubsidyRecordsByIds(ids));
    }
}
